package com.sc.nft.service.impl;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sc.nft.dao.ExportRecordsDao;
import com.sc.nft.dto.ExportRecordsDTO;
import com.sc.nft.entity.ExportRecords;
import com.sc.nft.entity.req.ExportRecordRpcRequest;
import com.sc.nft.entity.vo.ExportRecordsVO;
import com.sc.nft.enums.ExportRecordsTypeEnum;
import com.sc.nft.enums.ExportTypeEnum;
import com.sc.nft.enums.ExportTypeStatusEnum;
import com.sc.nft.service.ExportRecordsService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 朱梦晨
 * @Description: 导出记录
 * @date 2024-07-24
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class ExportRecordsServiceImpl implements ExportRecordsService {


    private final ExportRecordsDao exportRecordsDao;

    @Override
    public void addExportRecords(String exportName, Integer exportType, Integer status) {

        //Assert.isNull(exportRecordsDao.getByName(exportName), () -> new GlobalRunTimeException("名称已存在"));

        ExportRecords exportRecords = new ExportRecords();
        exportRecords.setExportName(exportName);
        exportRecords.setExportType(exportType);
        exportRecords.setStatus(status);
        exportRecords.setType(ExportRecordsTypeEnum.ADMIN);
        exportRecords.insert();
    }


    /**
     * 导出记录列表 Page
     *
     * @param exportRecordsDTO
     * @return
     */
    @Override
    public Page<ExportRecordsVO> exportRecordsList(ExportRecordsDTO exportRecordsDTO) {
        Page<ExportRecordsVO> exportRecordsVOPage = exportRecordsDao.exportRecordsList(exportRecordsDTO);
        return exportRecordsVOPage;
    }

    @Override
    public Page<ExportRecordsVO> exportDaoRecordsList(ExportRecordRpcRequest request) {
        Page<ExportRecordsVO> exportRecordsVOPage = exportRecordsDao.exportDaoRecordsList(request);
        List<ExportRecordsVO> records = exportRecordsVOPage.getRecords();
        for (ExportRecordsVO record : records) {
            record.setExportTypeText(ExportTypeEnum.getName(record.getExportType()).getName());
            record.setStatusText(ExportTypeStatusEnum.getName(record.getStatus()).getName());
        }
        return exportRecordsVOPage;
    }

}
